// pages/newThings/index.js
import { request } from "../../request/index.js";
import regeneratorRuntime from "../../lib/runtime/runtime";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [{ id: 0, value: "新鲜事", isActive: true }],
    // 新鲜事的数组
    newThingList:[],
    

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (){
    this.getNewthingList();
  },

  //将时间戳转换为标准时间
  timer(t){
    //年-月-日-时-分-秒
    let now = new Date(t)
    let year = now.getFullYear();
    let month = now.getMonth() + 1;
    let date = now.getDate();
    let hour = now.getHours();
    let minute = now.getMinutes();
    let second = now.getSeconds();
    // 补零
    if (month < 10) {
      month = "0" + month;
    }
    if (date < 10) {
      date = "0" + date;
    }
    if (hour < 10) {
      hour = "0" + hour;
    }
    if (minute < 10) {
      minute = "0" + minute;
    }
    if (second < 10) {
      second = "0" + second;
    }
    return (
      //按需求拼接   
      year + "-" + month + "-" + date
      // year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
    );
   },


  // 获取新鲜事列表数据
  async getNewthingList(){
    const res = await request({url:"/newthing/findAllNewThing"})
    console.log('新鲜事列表',res.data.data)
    let changeTimeList=res.data.data
    changeTimeList.forEach((v)=>{
        // console.log(v)
        v.create_time=this.timer(v.create_time)
        // console.log(v.create_time)
    })
    this.setData({
      newThingList:changeTimeList
    })
  },

  
})